// ABC414 D.cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;

  if (m == n) {
    cout << 0;
    return 0;
  }

  vector<ll> x(n);
  for (int i = 0; i < n; ++i)
    cin >> x[i];

  sort(x.begin(), x.end());

  vector<ll> gap;
  for (int i = 0; i < n - 1; ++i)
    gap.push_back(x[i + 1] - x[i]);

  sort(gap.begin(), gap.end());

  ll ans = 0;
  int k = (n - 1) - (m - 1);
  // 减去M  − 1 个间隔不包含任何基站。剩下的有M个“结合”
  for (int i = 0; i < k; ++i)
    ans += gap[i];

  cout << ans << '\n';

  return 0;
}